<template>
  <div>
    <el-row>
      <!-- 左侧维度选择 -->
      <el-col :span="5" class="leftDtf">
        <el-collapse v-model="activeName" accordion>
          <el-collapse-item title="内置维度" name="1">
            <template slot="title">
              <h6>内置维度</h6>
            </template>
            <div v-for="item in builtInList" :key="item.id" @dblclick="addDef(item)">
              {{ item.text }}
            </div>
          </el-collapse-item>
          <el-collapse-item title="自定义维度" name="2">
            <template slot="title">
              <h6>自定义维度</h6>
            </template>
            <div v-for="item in selfList" :key="item.id" @dblclick="addDef(item)">
              {{ item.text }}
            </div>
          </el-collapse-item>
        </el-collapse>
      </el-col>
      <!-- 右侧表格 -->
      <el-col :span="19" class="rightDtf" style="height:100%">
        <!-- 表头 -->
        <el-row class="defHeader">
          <el-col :span="2">关系</el-col>
          <el-col :span="3">维度</el-col>
          <el-col :span="4">运算符</el-col>
          <el-col :span="6">层级方案</el-col>
          <el-col :span="6">选择范围</el-col>
          <el-col :span="3"></el-col>
        </el-row>
        <br/>
        <!-- 表体 -->
         <el-row class="defBody">
           <!-- 循环每行 -->
           <el-row v-for="(item, i) in dataList" :key="i" style="display:flex">
           <!-- eslint-disable-next-line no-irregular-whitespace -->
          <el-col :span="2">{{i==0?'　　':'并且'}}</el-col>
          <el-col :span="3">
            <span style="color:red">*</span>{{ item.rullDictName }}
          </el-col>
          <el-col :span="4">
            <el-select
              v-model="dataList[i].conditionFlag"
              placeholder="请选择"
            >
              <el-option value="in" label="包含"></el-option>
              <el-option value="not in" label="不包含"></el-option>
            </el-select>
          </el-col>
          <el-col :span="6">
            <el-select
              v-model="dataList[i].rullAllVal"
              placeholder="请选择"
            >
              <el-option value="0003" label="科目树-全业务"></el-option>
              <el-option value="2" label="产品树-存款业务"></el-option>
              <el-option value="3" label="产品树-xx业务"></el-option>
            </el-select>
          </el-col>
          <el-col :span="6">
            <el-cascader
                  clearable
                  filterable
                  :options="treeList"
                  v-model="dataList[i].rullValTree"
                  :props="{
                    checkStrictly: true,
                    emitPath: false,
                    expendTrigger: 'hover'
                  }"
                  :show-all-levels="false"
                  :ref="'saveTree'"
                  @change="checkFormOrg(i)"
                ></el-cascader>
          </el-col>
          <el-col :span="3">
            <el-tag class="delRow" @click="delDef(i, dataList)">删除</el-tag >
            </el-col>
            
        </el-row>
         </el-row>
        <h4 class="tip">*双击左侧维度添加公式</h4>
      </el-col>
    </el-row>
  </div>
</template>

<script>
export default {
  name: "ruleDef",
  data() {
    return {
      activeName: "1",
      builtInList: [
        { id: "productCd", text: "产品" },
        { id: "ProductCd", text: "产品IES" },
        { id: "OrganUnit", text: "机构" },
        { id: "Industry", text: "行业代码" },
        { id: "GeneralLedger", text: "科目" },
        { id: "CustomerType", text: "客户类别代码" },
        { id: "BussinessUnit", text: "业务单元" },
        { id: "00004", text: "费用科目" },
        { id: "00003", text: "条线" },
        { id: "00001", text: "机构_CA" }
      ],
      selfList: [
        { id: "treasurer", text: "自营或司库" },
        { id: "match_id", text: "匹配字段" },
        { id: "VP_ALM_DIM_QZ", text: "债券种类" },
        { id: "OrganUnit_IES", text: "机构IES" },
        { id: "H001", text: "国银租赁利润中心" },
        { id: "EC_SUBJECT_KJ", text: "会计科目维度" },
        { id: "CustomerId", text: "客户" },
        { id: "CurrencyCd", text: "币种代码" },
        { id: "20200406", text: "科目国银" },
        { id: "201100", text: "存款" },
        { id: "130300", text: "贷款" },
        { id: "005", text: "机构维度" },
        { id: "001", text: "利率类型" },
        { id: "000001", text: "科目1" }
      ],
       treeList: [
        {
          value: "01",
          label: "一级业务",
          children: [{ value: "001", label: "二级业务" }]
        }
      ],
    };
  },
  props: {
    dataList: {
      type: Array,
      default: () => {
        return [];
      }
    }
  },
  methods: {
    // 处理删除
    delDef(index, rows) {
      rows.splice(index, 1);
    },
    // 处理树选中事件
    checkFormOrg(val) {
        let node = this.$refs['saveTree'][val].getCheckedNodes();
      this.$refs['saveTree'][val].dropDownVisible = false; // 隐藏模态框
    },
    addDef(item){
      let obj = {   creator: null,
          createdTm: null,
          modifier: null,
          modifiedTm: null,
          rullTermCode: null,
          caliberRullCode: null,
          caliberCode: null,
          caliberProjectCode: null,
          rullDictCode: "GeneralLedger",
          rullDictName: "科目",
          addFlag: null,
          conditionFlag: null,
          rullValTree: "1",
          rullVal: null,
          rullValName: "科目树",
          rullAllVal: "0003",
          sql: null,
          termSeq: null,
          rullDictVal: null
          }
          obj.rullDictCode = item.id,
          obj.rullDictName = item.text
    this.dataList.push(obj)
    }
  }
};
</script>

<style lang="scss" scoped>
.el-collapse-item div {
  cursor: pointer;
}
.leftDtf,
.rightDtf {
  border: 1px solid #ccc;
}
.leftDtf {
  padding: 0 15px;
}
.el-collapse-item div:hover {
  background-color: #d5dced;
}
.defHeader {
  height: 32px;
  border: 1px solid #ccc;
  line-height: 32px;
  display: block;
}
.rightDtf .el-row {
  height: 32px;
  line-height: 32px;
}
.rightDtf .el-col {
  text-align: center;
}
.rightDtf .defBody{
  height: 390px;
  border:1px solid #ccc;
  overflow: auto;
  margin-bottom: 20px;
  border-bottom:none ;
}
.delRow {
  cursor: pointer;
  color: #606266;
}
.tip {
  position: absolute;
  bottom: 5px;
  left: 240px;
  z-index: 999;
  font-size: 14px;
}
</style>